package com.smbms.entity;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class GreetingService {
//	定义局部切点
	@Pointcut("execution(* com.smbms.entity.*.*(..) )")
	public void pc(){
		
	}
	
//	切面前置增强
	@Before("pc()")
	public void myBefore(JoinPoint jp){
		System.out.println("start");
	}
	
//	后置增强
	@AfterReturning("pc()")
	public void myAfterReturning(JoinPoint jp){
		System.out.println("over");
	}
	
//	异常抛出增强
	@AfterThrowing(pointcut="pc()",throwing="e")
	public void myAfterThrowing(JoinPoint jp, RuntimeException e){
		System.out.println("3.异常抛出增强");
		e.printStackTrace();
	}
//	最终增强
	@After("pc()")
	public void myFinally(JoinPoint jp){
		System.out.println("4.最终增强");
		System.out.println("释放资源");
		
	}
	
//	环绕增强
	@Around("pc()")
	public void myAround(ProceedingJoinPoint jp) throws Throwable{
		System.out.println("5.环绕增强---开始");
		jp.proceed();
		System.out.println("5.环绕增强---结束");
	}
	
}
